stylecontext: Add a parent style cache
authorBenjamin Otte <otte@redhat.com>
Mon, 5 Jan 2015 23:38:54 +0000 (00:38 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 7 Jan 2015 13:26:48 +0000 (14:26 +0100)
commitfe33ee426a56255199f9a09727afdc9c302d62aa
tree5248489a8d54a35104f0f004a398c04eda3af60a
parent27285f1f0fb00bb4507a8bf3e426bef940ae41af
stylecontext: Add a parent style cache

We now cache the results of lookups on the parent GtkCssStyle. This
allows sharing styles between widgets (recursively). However, this
only works if the styles can't potentially depend on siblings -
neither directly via sibling selectors or via position pseudo-classes
like :first-child.
Unfortunately, Adwaita currently uses first-child a lot, and in
particular for labels, which are the most common widgets.

The big benefits of this change are both less CPU - due to not needing
to compute styles again - and less memory usage - due to sharing of
the styles between widgets. Here's some nonscientific numbers I
collected while pondering the usefulness of this patch:

                    glade   glade   widget
                    demo    demo    factory
                    runtime styles  styles
Adwaita before      19.1s   5800    1150
Adwaita now         18.9s   3800     970
Adwaita hacked now  14.5s   3100     910
simple before       11.3s   5800    1150
simple now          10.8s   1300     590

Adwaita: Adwaita as provided by GTK
Adwaita hacked: Adwaita with the first/last-child for GtkLabel removed
simple: A 250 lines simple GTK theme I use for testing
before: This patch not applied
now: this patch applied

glade demo runtime: Starting glade opening a large file and closing it
glade demo styles: GtkCssStaticStyle objects after opening glade with
                   the large file as per inspector
widget factory styles: GtkCssStaticStyle objects after startup as per
                       inspector
gtk/gtkstylecontext.c